Repository navigation
Conversation
A legacy server may reject server/discover with HTTP 200 and a JSON-RPC error while setting Mcp-Session-Id. The streamable client stored that ID and sent it on the fallback initialize, so a server that assigned a new session ID made Connect fail with "mismatching session IDs". server/discover is sessionless in 2026-07-28, and under 2025-11-25 the session ID belongs to the response carrying the InitializeResult, so the client no longer records a session ID from a server/discover response. Fixes modelcontextprotocol#1522 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment on lines
2668
to
2670
| if hadSessionID == "" { | ||
| c.sessionID = sessionID | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| if hadSessionID == "" && requestMethod == methodInitialize { | |
| c.sessionID = sessionID | |
| } |
According to spec sessionId should be set up only during initialize
A server MAY assign a session ID "at initialization time". It does this by putting it in an MCP-Session-Id header on the HTTP response that carries the InitializeResult
Adding this check here should be more clean
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A legacy server may reject
server/discoverwith HTTP 200 and a JSON-RPC error while settingMcp-Session-Id. The streamable client stored that ID and sent it on the fallbackinitialize, so a server that assigned a new session ID madeConnectfail withmismatching session IDs.server/discoveris sessionless in 2026-07-28, and under 2025-11-25 the session ID belongs to the response carrying theInitializeResult, so the client no longer records a session ID from aserver/discoverresponse.The new table test covers the HTTP 200 / -32601 case and four HTTP 400 rejection shapes seen from real legacy servers (plain text, -32600 with an unmatched id, -32600 with legacy-only
data.supported), each with a session ID on the discover response.Fixes #1522
AI disclosure: written with Claude Code; I reviewed the change and can explain it.